const app = getApp()
Page({
  data: {
    calendarData: [],
    isPersonal: false,
    imageList: [{
      id: 0,
      url: app.getImgUrl('slider1.webp'),
      link: ''
    }, {
      id: 1,
      url: app.getImgUrl('slider2.webp'),
      link: ''
    }, {
      id: 2,
      url: app.getImgUrl('slider3.webp'),
      link: ''
    }, {
      id: 3,
      url: app.getImgUrl('slider4.webp'),
      link: ''
    },],
    topLinkList: [
      { id: 0, title: '告警中心', icon: 'bell', link: '/pages/device/warnList/index' },
      { id: 1, title: '工单创建', icon: 'add-order', link: '/pages/work-order/creat/index' },
      { id: 2, title: '设备管理', icon: 'repair', link: '/pages/add-device/index' },
      { id: 3, title: '客户添加', icon: 'add-customer', link: "/pages/operation-center/add-customer/index" }
    ],
    chartData: [
      { value: 400, colorStart: '#52b3ff', colorEnd: '#418dff', label: '在线' },
      { value: 200, colorStart: '#106d9c', colorEnd: '#4599ce', label: '离线' },
      { value: 100, colorStart: '#48dbe4', colorEnd: '#5fe7ef', label: '故障' },
      { value: 100, colorStart: '#ffc646', colorEnd: '#ffcb5f', label: '维修' }
    ],
  },
  // 跳转设备详情
  godetail() {
    wx.navigateTo({
      url: '/pages/device/info/index',
    });
  },
  onLoad() {
    const chart = this.selectComponent('#chart')
    chart.draw()
    const dates = this.generateDates();
    this.setData({ calendarData: dates });
    const userType = wx.getStorageSync('userInfo').userType
    this.setData({
      isPersonal: parseInt(userType)
    })
  },
  generateDates() {
    const dates = [];
    const today = new Date();

    for (let i = 0; i < 14; i++) {
      const date = new Date();
      date.setDate(today.getDate() + i);

      dates.push({
        day: date.getDate(),
        weekDay: this.getWeekDay(date.getDay()),
        hasBadge: Math.random() > 0.7,
        value: (Math.random() * 10 + 1).toFixed(0)
      });
    }
    return dates;
  },

  getWeekDay(day) {
    const weekDays = ['日', '一', '二', '三', '四', '五', '六'];
    return `${weekDays[day]}`;
  },

  // 监听日期切换事件
  onDateChange(e) {
    console.log('激活的日期:', e.detail.date);
  },
  toggleMapMarker() {
    const mapMarker = this.selectComponent('#v-map')
    mapMarker.toggleMapMarker()
  },
  comitResult(res) {
    console.log(res)
  }
})
